#include "passworddialog.h"
#include "ui_passworddialog.h"

#include <QRegion>

PasswordDialog::PasswordDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PasswordDialog)
{
    ui->setupUi(this);
    ui->host_label->setHidden(true);
    ui->database_label->setHidden(true);
    ui->host_lineEdit->setHidden(true);
    ui->database_lineEdit->setHidden(true);
    ui->port_label->setHidden(true);
    ui->port_spinBox->setHidden(true);

    ui->user_lineEdit->setText(qApp->property("Username").toString());
    ui->pass_lineEdit->setText(qApp->property("Password").toString());
    ui->host_lineEdit->setText(qApp->property("Host").toString());
    ui->database_lineEdit->setText(qApp->property("Database").toString());
    ui->port_spinBox->setValue(qApp->property("Port").toInt());

    ui->local_checkBox->setChecked(qApp->property("LocalDatabase").toBool());
}

PasswordDialog::~PasswordDialog()
{
    delete ui;
}

void PasswordDialog::on_more_pushButton_clicked()
{
    ui->host_label->setHidden(false);
    ui->database_label->setHidden(false);
    ui->host_lineEdit->setHidden(false);
    ui->database_lineEdit->setHidden(false);
    ui->port_label->setHidden(false);
    ui->port_spinBox->setHidden(false);
    ui->more_pushButton->setHidden(true);
}

bool PasswordDialog::saveLogin() const
{
    return ui->save_checkBox->isChecked();
}

void PasswordDialog::setSaveLogin(const bool set)
{
    ui->save_checkBox->setChecked(set);
}

void PasswordDialog::on_local_checkBox_toggled(bool checked)
{
    ui->mysql_groupBox->setDisabled(checked);
}

void PasswordDialog::on_buttonBox_accepted()
{
    qApp->setProperty("LocalDatabase", ui->local_checkBox->isChecked());
    qApp->setProperty("Username", ui->user_lineEdit->text());
    qApp->setProperty("Password", ui->pass_lineEdit->text());
    qApp->setProperty("Host", ui->host_lineEdit->text());
    qApp->setProperty("Database", ui->database_lineEdit->text());
}
